<?php
	// Setup globals
	// @todo: Get these out of template
	global $wp_query;

	// Setup image width and height variables
	// @todo: Investigate if these are still needed here
	$image_width  = get_option( 'single_view_image_width' );
	$image_height = get_option( 'single_view_image_height' );
	
	$productskutag = get_post_meta($post->ID, 'productSKU', true) ;
	$productidtag = get_post_meta($post->ID, 'productID', true) ;
	if (get_post_meta($post->ID, 'productShipping', true) == 'Standard') {
		$shippingtype = 'Standard Shipping';
	} elseif (get_post_meta($post->ID, 'productShipping', true) == 'Freight') {
		$shippingtype = 'Freight Shipping';
	}
?>

<div id="single_product_page_container">

	<?php
		// Breadcrumbs
		wpsc_output_breadcrumbs();

		// Plugin hook for adding things to the top of the products page, like the live search
		do_action( 'wpsc_top_of_products_page' );
	?>

	<div class="single_product_display group">
<?php
		/**
		 * Start the product loop here.
		 * This is single products view, so there should be only one
		 */

		while ( wpsc_have_products() ) : wpsc_the_product(); ?>
					<div class="imagecol">
						<?php if ( wpsc_the_product_thumbnail() ) : ?>
								<a rel="<?php echo wpsc_the_product_title(); ?>" class="<?php echo wpsc_the_product_image_link_classes(); ?>" href="<?php echo esc_url( wpsc_the_product_image() ); ?>">
									<img class="product_image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php echo wpsc_the_product_title(); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo wpsc_the_product_thumbnail(); ?>"/>
								</a>
						<?php else: ?>
									<a href="<?php echo esc_url( wpsc_the_product_permalink() ); ?>">
									<img class="no-image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="No Image" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo WPSC_CORE_THEME_URL; ?>wpsc-images/noimage.png" width="<?php echo get_option('product_image_width'); ?>" height="<?php echo get_option('product_image_height'); ?>" />
									</a>
						<?php endif; ?>
					</div><!--close imagecol-->
                    
                    	<form class="product_form_small" enctype="multipart/form-data" action="<?php echo esc_url( wpsc_this_page_url() ); ?>" method="post" name="1" id="product_<?php echo wpsc_the_product_id(); ?>">

							<?php
							/**
							 * Quantity options - MUST be enabled in Admin Settings
							 */
							?>
							<div class="wpsc_product_price">
                            	<h5>Product Details &amp; Buy It Now!</h5>
								<p class="pricedisplay wpsc-product-price">Product: <span class="currentprice pricedisplay"><?php the_title(); ?></span></p>
								<p class="pricedisplay wpsc-product-price">SKU: <span class="currentprice pricedisplay"><?=$productskutag?></span></p>
								<?php wpsc_the_product_price_display(); ?>
								<p class="pricedisplay wpsc-product-price">Shipping: <span class="currentprice pricedisplay"><?=$shippingtype?></span></p>
							</div><!--close wpsc_product_price-->
                            	<fieldset>
                                	<input type="hidden" value="add_to_cart" name="wpsc_ajax_action" />
									<input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="product_id" />
									<div class="wpsc_quantity_update">
										<input type="text" id="wpsc_quantity_update_<?php echo wpsc_the_product_id(); ?>" name="wpsc_quantity_update" size="2" value="1" />
										<input type="hidden" name="key" value="<?php echo wpsc_the_cart_item_key(); ?>"/>
										<input type="hidden" name="wpsc_update_quantity" value="true" />
                                	</div><!--close wpsc_quantity_update-->
									<div class="wpsc_buy_button_container">
										<input type="submit" value="<?php _e('Add To Cart', 'wpsc'); ?>" name="Buy" class="wpsc_buy_button" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button"/>
										<div class="wpsc_loading_animation">
											<img title="Loading" alt="Loading" src="<?php echo wpsc_loading_animation_url(); ?>" />
											<?php _e('Updating cart...', 'wpsc'); ?>
										</div><!--close wpsc_loading_animation-->
									</div><!--close wpsc_buy_button_container-->
                                </fieldset>
							<?php do_action ( 'wpsc_product_form_fields_end' ); ?>
                            <div class="wpsc-form-cta">
								<p>Questions? Need Assistance?</p>
								<p class="small">Call Us Today... 1.877.786.6299</p>
							</div>
						</form><!--close product_form-->
                        
					<div class="productcol">
                    
						<?php do_action('wpsc_product_before_description', wpsc_the_product_id(), $wp_query->post); ?>
						<div class="product_description">
                        	<h3>Product Description</h3>
                            <div class="wpsc-product-docs-small">
								<h5>Product Documents</h5>
								<ul style="margin-bottom:10px;">
                                	<?php // Get The Link To The Product Brochure If It Exists
										if (get_post_meta($post->ID, 'productBrochureLink', true)) { ?>
											<li><a href="<?php meta('productBrochureLink'); ?>?output=pdf" target="_blank">Product Brochure</a></li>
									<?php } ?>
                                    <?php // Get The Link To The Product Datasheet If It Exists
										if (get_post_meta($post->ID, 'productDatasheetLink', true)) { ?>
											<li><a href="<?php meta('productDatasheetLink'); ?>?output=pdf" target="_blank">Product Datasheet</a></li>
									<?php } ?>
                                    <?php // Get The Link To The Product Installation Manual If It Exists
										if (get_post_meta($post->ID, 'productInstallManualLink', true)) { ?>
											<li><a href="<?php meta('productInstallManualLink'); ?>?output=pdf" target="_blank">Product Installation Manual</a></li>
									<?php } ?>
								</ul>
								<h5>Additional Resources</h5>
								<ul>
									<?php // Include Link To Press Release Page For Related Press Releases
										echo '<li><a href="http://www.sunmaxxsolar.com/product-press-releases.php?pid='.$productidtag.'&sku='.$productskutag.'" target="_blank">Related Press Releases</a></li>';
										echo '<li><a href="http://www.sunmaxxsolar.com/product-reference-projects.php?pid='.$productidtag.'&sku='.$productskutag.'" target="_blank">Related Reference Projects</a></li>';
										echo '<li><a href="http://www.sunmaxxsolar.com/product-tech-tips.php?pid='.$productidtag.'&sku='.$productskutag.'" target="_blank">Related FAQs &amp; Tech Tips</a></li>';
									?>
								</ul>
							</div>
							<?php echo wpsc_the_product_description(); ?>
                            
							<?php // Include Product Related Chart If Exists
								if (get_post_meta($post->ID, 'productChartCode', true)) {
									$chartcode = get_post_meta($post->ID, 'productChartCode', true);
									$charttitle = get_post_meta($post->ID, 'productChartTitle', true);
                                	echo '<h3>'.$charttitle.'</h3>';
									echo ''.$chartcode.'';
							} ?>
                            
                            <?php // Include Tag Based Image Gallery If Available
								if(get_post_meta($post->ID, 'productGalleryTitle', true)) { ?>
                                	<div id="accordian-wrapper" style="margin-bottom: 20px;">
									<div class="accbutton-images">
										<div class="accbutton-images-left"><?php meta('productGalleryTitle'); ?></div>
										<div class="accbutton-images-right">View Images</div>
									</div>
									<div class="acccontent-images">
										<?php 
											echo nggShowGallery( $productidtag );
										?>
									</div>
                                    </div>
								<?php } ?>
                            
						</div><!--close product_description -->
						<?php do_action( 'wpsc_product_addon_after_descr', wpsc_the_product_id() ); ?>
                        
                        <div style="width:100%;height:1px;background:#cccccc;clear:both;margin-top:10px;margin-bottom:10px;"></div>
                        
<?php // Get Related Upsell Products On Product Page
	query_posts('post_type=wpsc-product&showposts=4&wpsc_product_category=featured');
		if (have_posts()) { ?>
			<h3>Customers Also Viewed</h3>
				<?php while (have_posts()) : the_post(); ?>
					<div class="grid_product_view_box">
						<a href="<?php echo esc_url( wpsc_the_product_permalink() ); ?>">
							<?php if(wpsc_the_product_thumbnail()) : ?>
								<img class="product_image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php echo wpsc_the_product_title(); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo wpsc_the_product_thumbnail(); ?>"/>
							<?php else: ?>
								<img class="no-image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php esc_attr_e( 'No Image', 'wpsc' ); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo WPSC_CORE_THEME_URL; ?>wpsc-images/noimage.png" width="<?php echo get_option('product_image_width'); ?>" height="<?php echo get_option('product_image_height'); ?>" />
							<?php endif; ?>
							<h3><?php echo wpsc_the_product_title(); ?></h3>
							<?php wpsc_the_product_price_display(); ?>
							<p class="catButton">
								View Product Details
							</p>
							<div style="width:100%;height:0px;clear:both;"></div>
						</a>
					</div>
				<?php endwhile; wp_reset_query(); ?>
		<?php } else { ?>
			<p>There are no related products at this time.</p>
<?php } ?>

		</div><!--close single_product_display-->

    <?php endwhile;
	do_action( 'wpsc_theme_footer' ); ?>

</div><!--close single_product_page_container-->